<template>
  <div class="HuikuiInfoBatchFeedback el-card is-always-shadow el-card__body">
    <el-dialog
      title="批量回馈差异原因"
      :visible.sync="dialogVisible"
      @close="closed"
      width="950px">
      <avue-crud
        ref="crud"
        :option="optionTable"
        :data="listTable">
      </avue-crud>
      <avue-form :disabled="isReload" :option="option" v-model="formData" @submit="handleSubmit">
        <template  slot="qfReplyReason" slot-scope="scope">
          <el-select v-model="qfReplyReason" placeholder="请选择" style="width: 150px">
            <el-option
              v-for="(item,index) in qfReplyReasonList"
              :key="index"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </template>
        <template slot-scope="scope" slot="menuForm" >
          <el-button type="primary" @click="handleSubmit" >确认</el-button>
          <el-button @click="closed" >返回</el-button>
        </template>
      </avue-form>
    </el-dialog>
  </div>
</template>


<script>
  import {getForm, postForm} from '@/api/gen/gen'
  import ExportJsonExcel from "js-export-excel";
  import {fenExYuangettoFixed,getSysDictItemListToDict,getMappingStatus,getLineName,getStationName
  } from "../../../api/subwayRat/commonCheck";
  import {updateSwAuTvmCashAmountHierarchyDifferenceToHKBF} from "../../../api/clarifyManagement/JDZYDLCK";
  import ElInput from "../../../../node_modules/element-ui/packages/input/src/input";
  export default {
    components:{
      ElInput
    },
    data() {
      return {
        qfReplyReason :'',
        replySaleMoney:0,
        replyRechargeMoney:0,
        replyErrorReturnMoney:0,
        optionTable:{},
        listTable:[],
        option:{},
        isReload:true,
        dialogVisible:true,
        formData:{},
        qfReplyReasonList:[]
      }
    },
    created() {
      getSysDictItemListToDict({"type":"QF_REPLY_REASON"}).then((response)=>{
        this.qfReplyReasonList = response.data.data;
      });
      this.getOption();
      this.listTable = this.$parent.batchFeedbackList;
    },
    methods: {
      async handleSubmit(){
        if(!this.qfReplyReason || "" == this.qfReplyReason){
          this.$message.warning("请选择回馈差异原因！");
          return;
        }
        let list = [];
        for(let i=0;i<this.listTable.length;i++){
          list.push({id:this.listTable[i].id,payType:this.listTable[i].payType});
        }
        let p = {
          list:list,
          qfReplyReason:this.qfReplyReason,
          qfReplyDetail:this.formData.qfReplyDetail
        };
        await updateSwAuTvmCashAmountHierarchyDifferenceToHKBF(p).then((response)=>{
        });
        this.$parent.getList();
        this.closed();
      },
      closed(){
        this.dialogVisible=false;
        this.$parent.isShowDiaBatchFeedback=false;
      },
      getOption(){
        this.optionTable = {
          border: true,
          index: true,
          indexLabel: '序号',
          selection: false,
          reserveSelection:false,
          stripe: false,
          menuAlign: 'center',
          menu: false,
          viewBtn: false,
          editBtn: false,
          emptyBtn:false,
          delBtn: false,
          align: 'center',
          addBtn: false,
          column: [{
            fixed: true,
            label: '主键',
            prop: 'id',
            span: 24,
            type: 'input',
            hide: true
          },{
            hide: false,
            label: '线路名称',
            prop: 'lineCode',
            type: 'select',
            filterable : true,
            formatter: function(row, value , label, column){
              return getLineName(value);
            },
            search: false,
            display: true // 动态显隐控制不能删除
          }, {
            hide: false,
            label: '站点名称',
            prop: 'stationCode',
            type: 'select',
            filterable : true,
            formatter: function(row, value , label, column){
              return getStationName(row.lineCode,value);
            },
            search: false,
            display: true// 动态显隐控制不能删除
          },{
            width:120,
            label: '差异发生日期',
            prop: 'settleTime',
            type: 'datetime',
            format: 'yyyy-MM-dd',
            valueFormat: 'yyyy-MM-dd',
            search: false
          }, {
            hide: false,
            label: 'TVM编号',
            prop: 'tvmOrder',
          },{
            hide: false,
            label: '支付方式',
            prop: 'payType',
            formatter:function (row,v) {
              return getMappingStatus('xw_pay_type',v);
            }
          },{
            width:120,
            label: '售卖差异金额',
            prop: 'comparativeSelltkAmount',
            formatter:function (row,value , label, column) {
              let amount;
              // if(row.payType==1){
              //   if(row.compareType==1){
              //     amount = ((row.lcCashSellTicket-row.scCashSellTicket)/100).toFixed(2);
              //   }else{
              //     amount = ((row.accCashSellTicket-row.lcCashSellTicket)/100).toFixed(2);
              //   }
              // }else{
              //   if(row.compareType==1){
              //     amount = ((row.lcElecSellTicket-row.scElecSellTicket)/100).toFixed(2);
              //   }else{
              //     amount = ((row.accElecSellTicket-row.lcElecSellTicket)/100).toFixed(2);
              //   }
              // }
              if(row.payType==1){
                  amount = ((row.saleAmount-row.beSaleAmount)/100).toFixed(2);
              }else{
                  amount = ((row.saleAmount-row.beSaleAmount)/100).toFixed(2);
              }
              amount=Number(amount)?amount:'0.00';
              return amount;
            },
            search: false,
            hide: false,
          },{
            width:120,
            label: '充值差异金额',
            prop: 'comparativeInvestAmount',
            formatter:function (row,value , label, column) {
              let amount;
              // if(row.payType==1){
              //   if(row.compareType==1){
              //     amount = ((row.lcCashRecharge-row.scCashRecharge)/100).toFixed(2);
              //   }else{
              //     amount = ((row.accCashRecharge-row.lcCashRecharge)/100).toFixed(2);
              //   }
              // }else{
              //   if(row.compareType==1){
              //     amount = ((row.lcElecRecharge-row.scElecRecharge)/100).toFixed(2);
              //   }else{
              //     amount = ((row.accElecRecharge-row.lcElecRecharge)/100).toFixed(2);
              //   }
              // }
              if(row.payType==1){
                  amount = ((row.depositAmount-row.beDepositAmount)/100).toFixed(2);
              }else{
                  amount = ((row.depositAmount-row.beDepositAmount)/100).toFixed(2);
              }
              amount=Number(amount)?amount:'0.00';
              return amount;
            },
            search: false,
            hide: false,
          },{
            width:120,
            label: '退款差异金额',
            prop: 'comparativeFaretkAmount',
            formatter:function (row,value , label, column) {
              let amount;
              // if(row.payType==1){
              //   if(row.compareType==1){
              //     amount = ((row.lcCashReturn-row.scCashReturn)/100).toFixed(2);
              //   }else{
              //     amount = ((row.accCashReturn-row.lcCashReturn)/100).toFixed(2);
              //   }
              // }else{
              //   if(row.compareType==1){
              //     amount = ((row.lcElecReturn-row.scElecReturn)/100).toFixed(2);
              //   }else{
              //     amount = ((row.accElecReturn-row.lcElecReturn)/100).toFixed(2);
              //   }
              // }
              if(row.payType==1){
                  amount = ((row.errorRefundAmount-row.beErrorRefundAmount)/100).toFixed(2);
              }else{
                  amount = ((row.errorRefundAmount-row.beErrorRefundAmount)/100).toFixed(2);
              }
              amount=Number(amount)?amount:'0.00';
              return amount;
            },
            search: false,
            hide: false,
          },{
            label: '差异类型',
            prop: 'comparativeType',
            formatter:function(row, value , label, column){
              return value == 1?'SC-LC':'LC-ACC';
            },
            search: false
          }]
        };
        this.option={
          submitBtn:false,
          emptyBtn:false,
          group:[{
              icon:'',
              label: '',
              prop: 'group',
              column: [{
                label: '归属清分回馈差异原因',
                prop: 'qfReplyReason',
                formslot : true,
                labelWidth:130
              },{
                label: '清分人员详细描述',
                prop: 'qfReplyDetail',
                type:'textarea',
                labelWidth:130
              }]
            }]
        }
      }

    },
    mounted() {
    }
  }
</script>
